//
//  PlatformFunction.m
//  reSearchDemo
//
//  Created by 科技 on 15/8/1.
//  Copyright (c) 2015年 Kiwaro. All rights reserved.
//

#import "PlatformFunction.h"
#import "PlatformFunctionCell.h"
#import "MassTextingVC.h"
#import "MassRecordVC.h"
#import "ArticleManagement.h"
#import "AutoReply.h"
#import "ArticleCategoryVC.h"
#import "ArticleClassificationVC.h"
#import "ArticlePublishedVC.h"

@interface PlatformFunction ()<UITableViewDataSource,UITableViewDelegate>
{
    NSMutableArray *DataSource;  /**< 数据源 */
    UITableView *_tableView;     /**< tableView */
    NSMutableArray *CellArr;     /**< 存放cell 用于计算高度 */
    BOOL isLoad;                 /**< 判断是否第一次加载 */
}

@property (nonatomic, retain) OnePlatformModel *model;

@end

@implementation PlatformFunction


- (id)initWithPlatformModel:(OnePlatformModel *)model {
    self = [super init];
    if (self) {
        self.model = model;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor whiteColor];
    self.title = @"功能";
    [self setRightBarButtonImage:LOADIMAGE(@"btn_more") highlightedImage:nil selector:@selector(menuAction)];

    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) - 64) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.tableFooterView = [[UIView alloc] init];
    _tableView.separatorInset = UIEdgeInsetsMake(0, 0, 10, 0);
    [self.view addSubview:_tableView];
    
    //加载数据
    [self LoadModel];
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (isLoad) {
        _tableView.frame = CGRectMake(0, 0, self.view.width, self.view.height);
        isLoad = NO;
    }
}

-(void)menuAction {
    
}

#pragma mark -- 加载数据 --
-(void)LoadModel {
    NSArray *textArr = @[@"群发功能",@"群发历史",@"自动回复",@"文章管理",@"文章分类",@"文章发布"];
    NSArray *imageArr = @[@"图标1",@"图标2",@"图标3",@"图标4",@"图标5",@"图标6"];
    
    DataSource = [NSMutableArray array];
    CellArr = [NSMutableArray array];
    for (int i = 0; i<textArr.count; i++) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setObject:textArr[i] forKey:@"text"];
        [dic setObject:imageArr[i] forKey:@"image"];
        
        [DataSource addObject:dic];
        
        PlatformFunctionCell *cell = [[PlatformFunctionCell alloc] init];
        [CellArr addObject:cell];
    }

}

#pragma mark -
#pragma mark --tableviewDelegate--
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return DataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *indentifier = @"cell";
    PlatformFunctionCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    if (!cell) {
        cell = [[PlatformFunctionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier];
    }
    cell.model = DataSource[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    PlatformFunctionCell *cell = CellArr[indexPath.row];
    cell.model = DataSource[indexPath.row];
    return cell.height;
}
#pragma mark --设置分区高--
//-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
//    return 10;
//}
#pragma mark --
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    isLoad = YES;
    id viewController;
    switch (indexPath.row) {
        case 0:
            viewController = [MassTextingVC new];
            break;
        case 1:
            viewController = [MassRecordVC new];
            break;
        case 2:
            viewController = [AutoReply new];
            break;
        case 3:
            viewController = [ArticleManagement new];
            break;
//        case 4:
//        {
//            [self pushViewController:[ArticleCategoryVC new]];
//            break;
//        }
        case 4:
            viewController = [[ArticleClassificationVC alloc] initWithPlatformModel:self.model];
            break;
        case 5:
            viewController = [ArticlePublishedVC new];
            break;
        default:
            return;
    }
    [self pushViewController:viewController];

}

#pragma mark 重写状态样式方法
-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
